Skip to content

Fix slot deploy context value not being used #4617

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

nturinski
Copy link
Member

Summary

Fixed the deploySlot command to properly use the expectedContextValue parameter, ensuring that the "Deploy to Slot" command only shows slots in the picker, not production instances.

Changes

  • Modified the deploy function signature to properly use expectedContextValue instead of ignoring it
  • Added conditional logic to use pickFunctionApp with context filtering when expectedContextValue is provided and no target node is specified
  • Added import for pickFunctionApp utility function
  • Ensures the Deploy to Slot command behaves correctly by only showing deployment slots

Root Cause

The deploySlot function was creating an expectedContextValue parameter with the correct regex (ResolvedFunctionAppResource.pickSlotContextValue) but the deploy function was ignoring this parameter (prefixed with _). This meant that when users ran "Deploy to Slot" from the command palette, they would see all function apps (both production and slots) instead of just slots.

Testing

  • Manual testing can verify that "Deploy to Slot" command from command palette now only shows slots
  • The fix follows the same pattern used in other commands like swapSlot

Fixes #4354

Fixes #4599 - Cannot read properties of undefined (reading 'trim')
when backup template version file read returns null/undefined.

Added null check before calling toString().trim() on the file content
to provide a more actionable error message when backup version files
are missing or empty.
- Fixed deploySlot function to properly use expectedContextValue parameter
- Added logic to use pickFunctionApp with context filtering when deploying to slots
- Ensures Deploy to Slot command only shows slots in picker, not production instances

Fixes #4354
Copy link
Member Author

@nturinski nturinski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR addresses two separate issues:

  1. Deploy Command Context Value: Fixes slot deployment to properly use the expectedContextValue filtering
  2. Template Version Error Handling: Fixes the Cannot read properties of undefined (reading 'trim') error from Issue #4599

Both fixes are well-implemented and address the root causes correctly. However, there's a missing import for the localize function that needs to be added to prevent compilation errors.

The deploy logic improvement ensures that slot deployments show only deployment slots rather than all function apps, which improves the user experience. The template error handling provides better error messaging and prevents runtime crashes.

Overall good fixes, just needs the missing import resolved.

const node: SlotTreeItem = await getDeployNode(context, ext.rgApi.tree, arg1, arg2, async () => {
return await getOrCreateFunctionApp(context)
});
let node: SlotTreeItem;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good: Fixed slot deploy context value usage

The PR correctly addresses the deploy command logic by using expectedContextValue when it's provided and arg1 is undefined. This ensures that slot deploys properly filter to show only deployment slots rather than all function apps.

The addition of pickFunctionApp import and the conditional logic properly implements the intended behavior:

  • When deploying to slots (expectedContextValue is provided), use the filtered picker
  • Otherwise, use the existing deployment node logic

This fixes the issue where deploySlot command wasn't using its context filtering capability.

Review generated with Copilot

const versionContent = await AzExtFsExtra.readFile(await this.getBackupVersionPath());
if (!versionContent) {
throw new Error(localize('backupVersionFileEmpty', 'Backup template version file is empty or could not be read'));
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good: Fixed template version file error handling

This change properly addresses Issue #4599 where Cannot read properties of undefined (reading 'trim') error occurred when the backup template version file was empty or unreadable.

The fix adds appropriate null/undefined checking before calling .toString().trim(), providing a clear error message when the backup version file is problematic.

The error handling follows good practices:

  • Check for falsy values before proceeding
  • Throw a localized error message for better user experience
  • The error message is actionable (indicates the specific file is empty/unreadable)

Review generated with Copilot

return (await AzExtFsExtra.readFile(await this.getBackupVersionPath())).toString().trim();
const versionContent = await AzExtFsExtra.readFile(await this.getBackupVersionPath());
if (!versionContent) {
throw new Error(localize('backupVersionFileEmpty', 'Backup template version file is empty or could not be read'));
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Missing import for localize function

The code uses localize('backupVersionFileEmpty', ...) but there's no import statement for the localize function in this file.

This will cause a compilation error. You need to add:

import { localize } from '../localize';

at the top of the file with the other imports.

Review generated with Copilot

Didn't mean to include this.
@nturinski
Copy link
Member Author

@copilot Fix the linting errors

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Deploy to Slot action does not allow selecting deployment slot
1 participant